package cn.imvc.app.controllers.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Resource;
import cn.imvc.app.models.ResourceModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class ResourceControllerImpl implements ResourceController {
	public Page<Resource> page;
	public Resource resource;
	public ViewRequest viewRequest;
	public int id;
	public int[] ids;
	
	
	@Autowired
	ResourceModel resourceModel;
	
	public void setResource(Resource resource) {
		this.resource = resource;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public String search() {

		return "resource/search";
	}

	public String index() {
		page=resourceModel.find(viewRequest);
		return "resource/index";
	}

	public String show() {
		resource=resourceModel.get(id);
		return "resource/show";
	}
	public String detail(){
		resource=resourceModel.get(id);
		return "resource/detail";
	}

	public String editNew() {

		return "resource/editNew";
	}

	public String create() {
		resourceModel.save(resource);
		return Render.json(new DialogBean("200", "创建成功","resource", "closeCurrent"));
	}

	public String edit() {
		resource=resourceModel.get(id);
		return "resource/edit";
	}

	public String update() {
		resourceModel.update(id, resource);
		return Render.json(new DialogBean("200", "修改成功","resource", "closeCurrent"));
	}

	public String destroy() {
		resourceModel.delete(id);
		return Render.json(new DialogBean("200", "删除成功","resource"));
	}

	public String destroyBatch() {
		resourceModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功","resource"));
	}

}
